package com.zzl.bonds.ticket.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.zzl.bonds.ticket.constant.type.ApproveTypeEnum;
import com.zzl.bonds.ticket.dto.ApUserShowInfo;
import com.zzl.bonds.ticket.dto.TicketProcessUpdateDto;
import com.zzl.bonds.ticket.dto.feign.ApprovalAddDto;
import com.zzl.bonds.ticket.dto.feign.ApprovalSubmitDto;
import com.zzl.bonds.ticket.entity.TicketProcessEntity;
import com.zzl.bonds.ticket.exception.SysExceptionEnum;
import com.zzl.general.common.exception.SysException;
import com.zzl.general.common.serurity.entity.User;
import com.zzl.general.common.utils.PageUtils;

import java.util.List;
import java.util.Map;

/**
 * 票据审批流程表
 *
 * @author wztsl
 * @date 2021-11-30 14:48:47
 */
public interface TicketProcessService extends IService<TicketProcessEntity> {
    /**
     * 调用去审核接口
     *
     * @param checkSubmit 审核提交的信息
     * @param approveType 申请类型
     * @throws SysException 业务类型
     */
    void addTicketProcess(ApprovalSubmitDto checkSubmit, String approveType) throws SysException;

    /**
     * 分页查询
     *
     * @param params 查询参数
     * @return 分页数据
     */
    PageUtils queryPage(Map<String, Object> params);

    /**
     * 修改
     *
     * @param ticketProcessUpdateDto 修改实体
     * @param user                   当前登录用户
     * @throws SysException 业务异常
     */
    void updateTicketProcessById(TicketProcessUpdateDto ticketProcessUpdateDto, User user) throws SysException;

    /**
     * 获取当前登录人是否有对票据审核的操作
     *
     * @param ticketIdList 票据id集合
     * @param approveType  审批类型枚举值
     * @return 对应每个票据id，是否有审核操作标识
     * @throws SysException 系统异常
     */
    List<Boolean> getUserApproveFlags(List<String> ticketIdList, ApproveTypeEnum approveType) throws SysException;

    /**
     * 批量发起流程审批
     *
     * @param approvalProcessAddDto 批量流程
     * @param ticketIdList          开立申请id
     * @param user                  登录用户
     * @return boolean true代表流程开启，false 流程关闭，无需审批
     */
    boolean saveBatchTicketProcess(ApprovalAddDto approvalProcessAddDto, List<String> ticketIdList, ApproveTypeEnum approveType, User user) throws SysException;

    /**
     * 发起流程审批
     *
     * @param amount              交易金额
     * @param approveTypeTicketId 开立申请id
     * @param user                登录用户
     * @return boolean true代表流程开启，false 流程关闭，无需审批
     */
    boolean saveTicketProcess(Double amount, String approveTypeTicketId
            , String content, ApproveTypeEnum approvalType, User user, String enterpriseId, String applyType) throws SysException;

    /**
     * 回滚发起流程审批
     *
     * @param ticketAmount        交易金额
     * @param approveTypeTicketId 开立申请id
     * @param msg                 消息内容json
     * @param approveTypeEnum     审批类型枚举
     * @param user                登录用户
     * @param enterpriseId        签收方企业id
     * @return boolean true代表流程开启，false 流程关闭，无需审批
     * @throws SysException 调用RPC失败，获取或设置流程对应业务票据id时可能抛出异常
     */
    boolean rollbackSaveTicketProcess(Double ticketAmount, String approveTypeTicketId, String msg,
                                      ApproveTypeEnum approveTypeEnum, User user, String enterpriseId) throws SysException;

    /**
     * 打断票据审批流程
     * 例如：撤销业务申请时
     *
     * @param ticketId         票据id
     * @param approveTypeEnum  审批类型字典值
     * @param sysExceptionEnum 调用P服务终止审批流失败时抛出的异常
     * @throws SysException 调用P服务终止审批流时可能抛出异常
     */
    void interruptTicketProcess(String ticketId, ApproveTypeEnum approveTypeEnum, SysExceptionEnum sysExceptionEnum) throws SysException;

    /**
     * 发送审批到P服务
     *
     * @param ticket            票据对象
     * @param approveTypeEnum   审批类型
     * @param approvalSubmitDto 审批数据对象
     * @throws SysException 业务异常
     */
    void approvalSubmit(Object ticket, ApproveTypeEnum approveTypeEnum, ApprovalSubmitDto approvalSubmitDto) throws SysException;

    /**
     * 获取流程进度数据
     *
     * @param ticketId        票据id
     * @param approveTypeEnum 审批类型
     * @param enterpriseId    企业id
     * @return 流程进度集合
     * @throws SysException RPC接口可能抛出异常
     */
    List<ApUserShowInfo> getApUserShowInfoList(String ticketId, ApproveTypeEnum approveTypeEnum, String enterpriseId) throws SysException;

    List<ApUserShowInfo> getApUserShowInfoList(TicketProcessEntity ticketProcessEntity) throws SysException;
}

